<template>
    <!--    <div>载体</div>-->
    <div class="app-container">
        <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch">
            <el-form-item label="备份名称" prop="title">
                <el-input v-model="queryParams.bakName" placeholder="请输入备份名称" clearable style="width: 240px"
                    @keyup.enter.native="handleQuery" />
            </el-form-item>

            <el-form-item>
                <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
                <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>
        <el-row :gutter="10" class="mb8" ref="refbut">
            <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>

        <el-table ref="table" v-loading="loading" :data="dataList" :height="tableHeight"
            @selection-change="handleSelectionChange" border stripe>
            <el-table-column label="序号" sortable align="center" type="index" prop="id" />
            <el-table-column label="备份名称" prop="BAKNAME" align="center" :show-overflow-tooltip="true" />
            <el-table-column label="备份时间" prop="BAKTIME" align="center" :show-overflow-tooltip="true" />
            <el-table-column label="备份人" prop="BAKUSER" align="center" :show-overflow-tooltip="true" />
            <el-table-column label="所在部门" prop="BAKDEPT" align="center"></el-table-column>
            <el-table-column label="ip" prop="BAKUSERIP" align="center"></el-table-column>
            <el-table-column label="备份类型" prop="BAKTYPE" align="center">
                <template slot-scope="scope">
                    {{ scope.row.BAKTYPE=="1"?'表':'模式' }}
                </template>
            </el-table-column>
            <el-table-column label="备份方式" prop="BAKSTATE" align="center">
                <template slot-scope="scope">
                    {{ scope.row.BAKSTATE=="1"?'自行备份':'手动备份' }}
                </template>
            </el-table-column>
            <el-table-column label="备份目录" prop="BAKFILE" align="center"></el-table-column>
            <el-table-column label="操作" align="center">
                <template slot-scope="scope">
                    <el-button plain type="success" size="mini" @click="handleRestore(scope.row)">还原</el-button>
                </template>
            </el-table-column>
        </el-table>
        <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
            @pagination="getList" />


    </div>
</template>

<script>
import estimateTableHeight from "@/mixins/estimateTableHeight";

import {getBackDaLogLists,recoveryData} from "@/api/cqbc/backupRestore/databaseRestoreManagement.js"

export default {
    mixins: [estimateTableHeight], // 混入方法
    archive_Dicts: ['CARRIER_TYPE'],
    data() {
        return {
            loading: true,
            // 选中数组
            ids: [],
            // 非单个禁用
            single: true,
            // 非多个禁用
            multiple: true,
            // 显示搜索条件
            showSearch: true,
            dataList: [],
            total: 0,
            queryParams: {
                pageNum: 1,
                pageSize: 10,
                bakName:undefined
            },


        }
    },
    created() {
        this.getList()
    },
    methods: {
        getList() {
            getBackDaLogLists(this.queryParams).then(response => {
                this.dataList = response.rows
                this.total = response.total
                this.loading = false
            })
        },

        handleQuery(){
            this.getList();
        },
        resetQuery(){
            this.queryParams= {
                pageNum: 1,
                pageSize: 10,
                name:undefined
            },
            this.getList();
        },
        table_index(index) {
            return (this.queryParams.pageNum - 1) * this.queryParams.pageSize + index + 1;
        },
        // 多选框选中数据
        handleSelectionChange(selection) {
            this.ids = selection.map(item => item.id)
            this.single = selection.length !== 1
            this.multiple = !selection.length
        },

        handleRestore(row) {
            const id = row.BAKLOGID
            this.$modal.confirm('是否确认还原名称为"' + row.BAKNAME + '"的数据项？').then(function () { }).then(() => {
                recoveryData({id:id}).then(res => {
                    if (res.code == "200") {
                        this.$modal.msgSuccess("还原成功");
                        this.getList();
                    }
                })
            }).catch(() => { });
        },


    }
}
</script>

<style></style>
